﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x0200002C RID: 44
[RequireComponent(typeof(Text))]
public class ColorLabel : MonoBehaviour
{
	// Token: 0x060000E1 RID: 225 RVA: 0x0000BE9F File Offset: 0x0000A09F
	private void Awake()
	{
		this.label = base.GetComponent<Text>();
	}

	// Token: 0x060000E2 RID: 226 RVA: 0x0000BEB0 File Offset: 0x0000A0B0
	private void OnEnable()
	{
		if (Application.isPlaying && this.picker != null)
		{
			this.picker.onValueChanged.AddListener(new UnityAction<Color>(this.ColorChanged));
			this.picker.onHSVChanged.AddListener(new UnityAction<float, float, float>(this.HSVChanged));
		}
	}

	// Token: 0x060000E3 RID: 227 RVA: 0x0000BF10 File Offset: 0x0000A110
	private void OnDestroy()
	{
		if (this.picker != null)
		{
			this.picker.onValueChanged.RemoveListener(new UnityAction<Color>(this.ColorChanged));
			this.picker.onHSVChanged.RemoveListener(new UnityAction<float, float, float>(this.HSVChanged));
		}
	}

	// Token: 0x060000E4 RID: 228 RVA: 0x0000BF66 File Offset: 0x0000A166
	private void ColorChanged(Color color)
	{
		this.UpdateValue();
	}

	// Token: 0x060000E5 RID: 229 RVA: 0x0000BF66 File Offset: 0x0000A166
	private void HSVChanged(float hue, float sateration, float value)
	{
		this.UpdateValue();
	}

	// Token: 0x060000E6 RID: 230 RVA: 0x0000BF70 File Offset: 0x0000A170
	private void UpdateValue()
	{
		if (this.picker == null)
		{
			this.label.text = this.prefix + "-";
		}
		else
		{
			float value = this.minValue + this.picker.GetValue(this.type) * (this.maxValue - this.minValue);
			this.label.text = this.prefix + this.ConvertToDisplayString(value);
		}
	}

	// Token: 0x060000E7 RID: 231 RVA: 0x0000BFF4 File Offset: 0x0000A1F4
	private string ConvertToDisplayString(float value)
	{
		if (this.precision > 0)
		{
			return value.ToString("f " + this.precision);
		}
		return Mathf.FloorToInt(value).ToString();
	}

	// Token: 0x040001E8 RID: 488
	public ColorPicker picker;

	// Token: 0x040001E9 RID: 489
	public ColorValues type;

	// Token: 0x040001EA RID: 490
	public string prefix = "R: ";

	// Token: 0x040001EB RID: 491
	public float minValue;

	// Token: 0x040001EC RID: 492
	public float maxValue = 255f;

	// Token: 0x040001ED RID: 493
	public int precision;

	// Token: 0x040001EE RID: 494
	private Text label;
}
